#include <cctype>
#include <cstdio>

typedef long long ll;
const int N = 10000001;
int n, top = 1, cnt;
int stk[N], p[N];

inline int read() {
  int x = 0, ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
  return x;
}

struct Node {
  int ls, rs;
} tr[N];

void build() {
  for (int i = 1; i <= n; ++i) {
    int cur = top;
    while (cur && p[stk[cur]] > p[i]) --cur;
    if (cur) tr[stk[cur]].rs = i;
    if (cur < top) tr[i].ls = stk[cur + 1];
    stk[++cur] = i;
    top = cur;
  }
}

int main() {
  n = read();
  for (int i = 1; i <= n; ++i) {
    p[i] = read();
  }
  build();
  ll ansl = 0, ansr = 0;
  for (int i = 1; i <= n; ++i) {
    ansl ^= 1ll * i * (tr[i].ls + 1);
    ansr ^= 1ll * i * (tr[i].rs + 1);
  }
  printf("%lld %lld", ansl, ansr);
  return 0;
}